package com.pengtu.entity.project;

import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OrderBy;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;

import com.pengtu.entity.IdEntity;
import com.pengtu.entity.app.Department;
import com.pengtu.utils.reflection.ConvertUtils;
/**
 * 施工合同段
 * 
 * SignUpContract
 * 
 * 2011-7-27 下午02:11:12
 * 
 * @version 1.0.0
 *
 */
@Entity
@Table(name = "T_PROJ_SIGNUPCONTRACT")
public class SignUpContract extends IdEntity {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private String projectId;
	private String orgCode;
	private String contractOrder;
	private String contractNum;
	private String contractKind;
	private String startPegNum;
	private String endPegNum;
	private Date beginDate;
	private Date endDate;
	private Department branchOrgCode;
	private Double contractCost;
	private String contractContent;
	private String remark;
	private String principal ;
	private Set<DrawingsContractInfo> contractSet = new HashSet<DrawingsContractInfo>();

	@Column(name = "PROJECTID")
	public String getProjectId() {
		return projectId;
	}

	public void setProjectId(String projectId) {
		this.projectId = projectId;
	}

	@Column(name = "ORGCODE")
	public String getOrgCode() {
		return orgCode;
	}

	public void setOrgCode(String orgCode) {
		this.orgCode = orgCode;
	}

	@Column(name = "CONTRACTORDER")
	public String getContractOrder() {
		return contractOrder;
	}

	public void setContractOrder(String contractOrder) {
		this.contractOrder = contractOrder;
	}

	@Column(name = "CONTRACTNUM")
	public String getContractNum() {
		return contractNum;
	}

	public void setContractNum(String contractNum) {
		this.contractNum = contractNum;
	}

	@Column(name = "CONTRACTKIND")
	public String getContractKind() {
		return contractKind;
	}

	public void setContractKind(String contractKind) {
		this.contractKind = contractKind;
	}

	@Column(name = "STARTPEGNUM")
	public String getStartPegNum() {
		return startPegNum;
	}

	public void setStartPegNum(String startPegNum) {
		this.startPegNum = startPegNum;
	}

	@Column(name = "ENDPEGNUM")
	public String getEndPegNum() {
		return endPegNum;
	}

	public void setEndPegNum(String endPegNum) {
		this.endPegNum = endPegNum;
	}

	@Column(name = "BEGINDATE")
	public Date getBeginDate() {
		return beginDate;
	}

	public void setBeginDate(Date beginDate) {
		this.beginDate = beginDate;
	}

	@Column(name = "ENDDATE")
	public Date getEndDate() {
		return endDate;
	}

	public void setEndDate(Date endDate) {
		this.endDate = endDate;
	}

	@Column(name = "CONTRACTCOST")
	public Double getContractCost() {
		return contractCost;
	}

	public void setContractCost(Double contractCost) {
		this.contractCost = contractCost;
	}

	@Column(name = "CONTRACTCONTENT")
	public String getContractContent() {
		return contractContent;
	}

	public void setContractContent(String contractContent) {
		this.contractContent = contractContent;
	}

	@Column(name = "REMARK")
	public String getRemark() {
		return remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}
	
	

	@ManyToMany(targetEntity = DrawingsContractInfo.class, cascade = CascadeType.MERGE)
	@JoinTable(name = "R_PROJ_CONTRACTREGARD", joinColumns = { @JoinColumn(name = "SIGNID", referencedColumnName = "id") }, inverseJoinColumns = { @JoinColumn(name = "CONTRACTID", referencedColumnName = "id") })
	// Fecth策略定义
	@Fetch(FetchMode.SUBSELECT)
	// 集合按id排序.
	@OrderBy("id")
	// 集合中对象id的缓存.
	@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
	public Set<DrawingsContractInfo> getContractSet() {
		return contractSet;
	}

	public void setContractSet(Set<DrawingsContractInfo> contractSet) {
		this.contractSet = contractSet;
	}
	
	// 非持久化属性.
	@Transient
	@SuppressWarnings("unchecked")
	public List<String> getDrawIds() {
		return ConvertUtils.convertElementPropertyToList(contractSet, "id");
	}
	
	
	@ManyToOne(cascade=CascadeType.ALL)
	@JoinColumn(name="BRANCHORGCODE")
	public Department getBranchOrgCode() {
		return branchOrgCode;
	}

	public void setBranchOrgCode(Department branchOrgCode) {
		this.branchOrgCode = branchOrgCode;
	}

	
	@Column(name="PRINCIPAL")
	public String getPrincipal() {
		return principal;
	}

	public void setPrincipal(String principal) {
		this.principal = principal;
	}

	public SignUpContract() {
		super();
	}

}
